// pages/custom-tab/issue/issue.js
var app = getApp();
Component({

  lifetimes: {
    attached() {
      // 在组件实例进入页面节点树时执行
      this.getProjectList();
      // this.getUserInfo()
      wx.setNavigationBarTitle({
        title: '首页'
      })
    },
    detached() {
      // 在组件实例被从页面节点树移除时执行
    },
  },

  /* 开启全局样式设置 */
  options: {
    addGlobalClass: true,
  },

  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    iconList: [{
      icon: 'cardboardfill',
      color: 'red',
      badge: 120,
      name: '课堂',
      type: 1
    }, {
      icon: 'recordfill',
      color: 'orange',
      badge: 1,
      name: '会议',
      type: 2
    }, {
      icon: 'discoverfill',
      color: 'blue',
      badge: 0,
      name: '活动',
      type: 3
    }, {
      icon: 'scan',
      color: 'yellow',
      badge: 0,
      name: '扫一扫',
      type: 100
    }],
    gridCol: 4,
    skin: false,

    projectList: [],

    loadModal:true


  },

  /**
   * 组件的方法列表
   */
  methods: {

    getProjectList: function (e) {
      var that = this
      wx.request({
        url: app.host + '/project/search',
        data: {
          name: ""
        },
        header: {
          accessToken: app.accessToken
        },
        method: "post",
        complete: function (res) {
          console.log(res)
          if (res.statusCode == 200) {
            if (res.data.code == 0) {
              that.setData({
                projectList: res.data.data,
              })
            }
          }
          that.setData({
            loadModal:false
          })
        }
      })
    },
    //获取用户个人信息
    getUserInfo: function () {
      var that = this;
      wx.request({
        url: app.host + '/user/info/',
        header: {
          accessToken: app.accessToken
        },
        method: 'GET',
        complete: function (res) {
          if (res.data.code == 0) {
            that.setData({
              userInfo: res.data.data
            })
          }
          wx.hideLoading()
        }
      })
    },
    toSearch: function (e) {
      var type = e.currentTarget.dataset.type
      if (type == 100) {
        console.log("打开扫一扫")
        // 只允许从相机扫码
        wx.scanCode({
          onlyFromCamera: true,
          success(res) {
            console.log(res)
            var path = res.path
            console.log(path)
            wx.navigateTo({
              url: "/" + path,
            })
          }
        })
        return
      } else {
        wx.navigateTo({
          url: '/pages/search/search?type=' + type,
        })
      }

    },
    toProjectDetail: function (e) {
      console.log(e)
      var id = e.currentTarget.dataset.id
      var num = e.currentTarget.dataset.num
      wx.navigateTo({
        url: '/pages/portal/project/detail/detail?id=' + id + "&num=" + num,
      })
    }
  }
})